package test;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.DocumentException;

import com.alibaba.fastjson.JSONObject;

import aorey.database.DataBaseConfigAction;
import aorey.database.DataBaseConfigTransactionAction;
import aorey.database.DataConfig;
import aorey.database.DataTag;
import aorey.database.DataTransactionConfigInfo;
import aorey.database.config.DataConfigTransAction;
import aorey.notice.Message;

/**
 * Servlet implementation class b
 */
@WebServlet("/b")
public class b extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public b() {
        super();
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Message msg = new Message();
		DataBaseConfigAction dataBaseConfigAction = new DataBaseConfigAction(request);
		msg = dataBaseConfigAction.select("stest");
		response.getWriter().println(msg.toString());
//		msg = dataBaseConfigAction.delete("dtest");
//		msg = dataBaseConfigAction.insert("itest");
//		msg = dataBaseConfigAction.update("utest");
//		response.getWriter().println(msg.toString());
		
//		DataTransactionConfigInfo dataTransactionConfigInfo = new DataTransactionConfigInfo(request);
		
		try {
			DataBaseConfigTransactionAction dataBaseConfigTransactionAction = new DataBaseConfigTransactionAction();
//			msg = dataBaseConfigTransactionAction.actionTransaction("t", request);
//			response.getWriter().println(msg.toString());
//			if (msg.state.equals("0")) {
//				response.getWriter().println("OK");
//			}
//			else
//			{
//				response.getWriter().println(msg.error);
//			}
//			DataTag dataTag = new DataTag(request);
//			HashMap<String, String> data = new  HashMap<String, String>();
//			JSONObject jsonObject = JSONObject.parseObject("{a:1,b:2}");
//			data.put("node1", "[{a:1,b:2},{a:3,b:4}]");
//			dataTag.dataReplace("tag={$record.node1.a};", jsonObject);
//			DataConfigTransAction  dataConfigTransAction = dataBaseConfigTransactionAction.actionTransaction("t", request);
//			dataBaseConfigTransactionAction.actionTransaction("t", request);
//			dataTransactionConfigInfo.getTransaction("t");
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		response.getWriter().close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
